home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / strncase.c < prev    next >
C/C++ Source or Header  |  1995-09-05  |  2KB  |  54 lines

  1. /* Copyright (C) 1992 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public
  15. License along with the GNU C Library; see the file COPYING.  If
  16. not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  17. Boston, MA  02111-1307, USA.  */
  18.  
  19. #ifdef HAVE_CONFIG_H
  20. #include <config.h>
  21. #endif
  22.  
  23. #ifndef HAVE_STRNCASECMP
  24.  
  25. #include <ctype.h>
  26. #include <string.h>
  27.  
  28. /* Compare no more than N characters of S1 and S2,
  29.    ignoring case, returning less than, equal to or
  30.    greater than zero if S1 is lexicographically less
  31.    than, equal to or greater than S2.  */
  32. int
  33. strncasecmp (const char *s1, const char *s2, size_t n)
  34. {
  35.   register const unsigned char *p1 = (const unsigned char *) s1;
  36.   register const unsigned char *p2 = (const unsigned char *) s2;
  37.   unsigned char c1, c2;
  38.  
  39.   if (p1 == p2 || n == 0)
  40.     return 0;
  41.  
  42.   do
  43.     {
  44.       c1 = tolower (*p1++);
  45.       c2 = tolower (*p2++);
  46.       if (c1 == '\0' || c1 != c2)
  47.     return c1 - c2;
  48.     } while (--n > 0);
  49.  
  50.   return c1 - c2;
  51. }
  52.  
  53. #endif
  54.